package com.singzi.leetcode.N600;

public class T0537 {
    public static void main(String[] args) {
        Solution0537 solution0537 = new Solution0537();
        System.out.println(solution0537.complexNumberMultiply("6+-6i", "5+9i"));
    }
}
class Solution0537 {
    public String complexNumberMultiply(String num1, String num2) {

        int firstReal, firstImag, secondReal, secondImag, real, imag;
        int endIndex = 1;
        for(int i = 0;i <num1.length();i++){
            if(num1.charAt(i) == '+') endIndex = i;
        }
        firstReal = Integer.parseInt(num1.substring(0, endIndex));
        firstImag = Integer.parseInt(num1.substring(endIndex+1,num1.length()-1));
        for(int i = 0;i <num2.length();i++){
            if(num2.charAt(i) == '+') endIndex = i;
        }
        secondReal = Integer.parseInt(num2.substring(0, endIndex));
        secondImag = Integer.parseInt(num2.substring(endIndex+1,num2.length()-1));
        real = firstReal*secondReal + firstImag*secondImag*(-1);
        imag = firstReal*secondImag + firstImag*secondReal;

        return real + "+" + imag + "i";
    }

}